package com.xlkj.ms.tools.core.commons.exceptions;


import com.xlkj.ms.tools.core.commons.DefaultRetCode;

/**
 * 调用方可以继承该异常类
 * <ul>
 *     <li>如果是业务错误（如：查询失败）实现对业务错误的抛出，这个抛出的“异常”会被切面捕获，并按照一定的格式进行响应，这样业务代码中就不需要过多的关心错误响应的组包、响应，都由切面来完成</strong></li>
 *     <li>如果是非业务异常（非检查异常或者检查异常）也会被切面捕获，并且按照一定的格式进行响应</li>
 * </ul>
 *
 * @author zhuqifeng
 * @date 2021/11/10 11:53
 * @package com.xlkj.ms.tools.core.commons.exceptions
 */
public class CommonsBizException extends CustomizeBizException{

    private static final long serialVersionUID = 8137555693326936698L;

    protected String code;

    protected String msg;

    public CommonsBizException() {
        super();
    }

    public CommonsBizException(DefaultRetCode retCode) {
        super();
        this.code = retCode.getCode();
        this.msg = retCode.getMsg();
    }

    public CommonsBizException(String code, String message) {
        super();
        this.code = code;
        this.msg = message;
    }

    /**
     * 错误信息中包含通配符，需要替换的构造方法
     * @param retCode
     * @param needReplaceMsgs 需要被替换的错误信息
     */
    public CommonsBizException(DefaultRetCode retCode, String... needReplaceMsgs){
        super();
        this.code = retCode.getCode();
        this.msg = DefaultRetCode.changeRetCode(retCode, needReplaceMsgs);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String getMessage() {
        return msg;
    }
}